let ul=document.querySelector('.main ul')
let xhr =new XMLHttpRequest()
xhr.open('get','http://chst.vip:1234/api/getcouponproduct?couponid='+localStorage.getItem('couponId'),true)
xhr.onload=function(){
    if(xhr.status===200){
        let res =JSON.parse(xhr.responseText)
        let an=res .result
        let lis=''
        console.log(an);
        an.forEach(item => {
         lis+=`<li couponProductId=${item.couponProductId}>
                    ${item.couponProductImg }
                    <div class="one">
                        <p>${item.couponProductName}</p>
                        <p>${item.couponProductPrice}</p>
                        <p>${item.couponProductTime}</p>
                    </div>
                </li>
            ` 
        });
        ul.innerHTML=lis

    }
}
xhr.send(null)
let all=document.querySelector('.all')
let cha=document.querySelector('.all .img .cha')
let one=document.querySelector('.all .img .one')

// 点击图片显示轮播图
ul.onclick=function(e){
    var e=e || window.event
    var target=e.target || e.srcElement
    let a=0
    if(target.nodeName==='IMG'){
        all.style.transform='translateY(0px)' 
        a=target.parentNode.getAttribute('couponProductId')
        console.log(a);
        let xhr =new XMLHttpRequest()
        xhr.open('get','http://chst.vip:1234/api/getcouponproduct?couponid='+localStorage.getItem('couponId'),true)
        xhr.onload=function(){
            if(xhr.status===200){
                let res =JSON.parse(xhr.responseText)
                let an=res .result
                let lis=''
                an.forEach(item => {
                lis=`
                    ${an[a].couponProductImg}
                    ` 
                });
                one.innerHTML=lis
            }
        }
        xhr.send(null)

        all.onclick=function(e){
            var e=e || window.event
            var target=e.target || e.srcElement
            if(target.nodeName==='P'){
                console.log(a);
                a--
                if(a<0){
                    a=0
                }
                let xhr =new XMLHttpRequest()
                xhr.open('get','http://chst.vip:1234/api/getcouponproduct?couponid='+localStorage.getItem('couponId'),true)
                xhr.onload=function(){
                    if(xhr.status===200){
                        let res =JSON.parse(xhr.responseText)
                        let an=res .result
                        let lis=''
                        an.forEach(item => {
                        lis=`
                            ${an[a].couponProductImg}
                            ` 
                        });
                        one.innerHTML=lis
                    }
                }
                xhr.send(null)
            } 
            if(target.nodeName==='NAV'){
                console.log(a);
                a++
                if(a>53){
                    a=53
                }
                let xhr =new XMLHttpRequest()
                xhr.open('get','http://chst.vip:1234/api/getcouponproduct?couponid='+localStorage.getItem('couponId'),true)
                xhr.onload=function(){
                    if(xhr.status===200){
                        let res =JSON.parse(xhr.responseText)
                        let an=res .result
                        let lis=''
                        an.forEach(item => {
                        lis=`
                            ${an[a].couponProductImg}
                            ` 
                        });
                        one.innerHTML=lis
                    }
                }
                xhr.send(null)
            } 

        }
    }
}
cha.onclick=function(){
    all.style.transform='translateY(-1000px)'  
}
